package com.zking.dao;

import java.sql.SQLException;
import java.util.List;

import com.zking.entity.User;

public class UserDao extends BaseDaoImpl {

	/**
	 * 查询所有的用户数据
	 * 
	 * @return
	 */
	public List<User> queryStudents() {
		String sql = "select * from User";
		try {
			return findList(User.class, sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	public List<User> queryName(String name) {
		String sql = "select * from User WHERE `userName` = '" + name + "';";
		try {
			return findList(User.class, sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 插入一条数数据
	 * 
	 * @param user
	 * @return
	 */
	public int insertStudent(User user) {
		String sql = "insert into user values(?,?,?,?,?)";
		Object[] params = { user.getUserName(), user.getPassWord(), user.getPhoneNumber(), user.getShopname(),user.getSort()};
		try {
			return update(sql, params);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return 0;
	}

	/**
	 * 修改数据
	 * 
	 * @param
	 * @return
	 */
	public int updateUser(String passWord,String userName) {
		String sql = "UPDATE `rz1217db_2`.`user` SET `passWord` = ? WHERE `userName` = ?";
		Object[] params = {passWord,userName};
		try {
			return update(sql, params);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return 0;
	}


	/**
	 * 删除数据
	 * 
	 * @return
	 *//*
		 * public int deleteStudent(int id) { String sql =
		 * "delete from student1 where id=?"; Object[] params = {id}; try { return
		 * update(sql, params); } catch (SQLException e) { e.printStackTrace(); } return
		 * 0; }
		 */

}
